﻿#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "filter/medianFilter2D.h"

using Catch::Matchers::WithinAbs;
using std::vector;

TEST_CASE("medianFilter2D", "[medianFilter2D]")
{
    vector<vector<double>> image = {
        {1, 2,   3},
        {4, 100, 6},
        {7, 8,   9}  // 含噪声
    };
    auto filtered = medianFilter2D(image, 3);

    CHECK_THAT(filtered[0][0], WithinAbs(4, 0.1));
    CHECK_THAT(filtered[0][1], WithinAbs(4, 0.1));
    CHECK_THAT(filtered[0][2], WithinAbs(6, 0.1));
    CHECK_THAT(filtered[1][0], WithinAbs(7, 0.1));
    CHECK_THAT(filtered[1][1], WithinAbs(6, 0.1));
    CHECK_THAT(filtered[1][2], WithinAbs(8, 0.1));
    CHECK_THAT(filtered[2][0], WithinAbs(8, 0.1));
    CHECK_THAT(filtered[2][1], WithinAbs(8, 0.1));
    CHECK_THAT(filtered[2][2], WithinAbs(9, 0.1));
}
